package com.bilibili.lzx.api;

import com.bilibili.lzx.api.support.UserSupport;
import com.bilibili.lzx.dao.domain.FollowingGroup;
import com.bilibili.lzx.dao.domain.JsonResponse;
import com.bilibili.lzx.dao.domain.UserFollowing;
import com.bilibili.lzx.service.FollowingGroupService;
import com.bilibili.lzx.service.UserFollowingService;
import com.bilibili.lzx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author lzx
 * @date 2024/8/25 13:39
 */
@RestController
public class UserFollowingApi {

    @Resource
    private UserFollowingService userFollowingService;

    @Resource
    private FollowingGroupService followingGroupService;

    @PostMapping("/user-followings")
    public JsonResponse<String> addUserFollowing(@RequestBody UserFollowing userFollowing){
        Long currentUserId = UserSupport.getCurrentUserId();
        userFollowing.setUserId(currentUserId);
        userFollowingService.addUserFollowing(userFollowing);
        return JsonResponse.success();
    }

    @GetMapping("/user-followings")
    public JsonResponse<List<FollowingGroup>> getUserFollowings(){
        Long currentUserId = UserSupport.getCurrentUserId();
        List<FollowingGroup> userFollowings = userFollowingService.getUserFollowings(currentUserId);
        return new JsonResponse<>(userFollowings);
    }

    @GetMapping("/user-fans")
    public JsonResponse<List<UserFollowing>> getUserFans(){
        Long currentUserId = UserSupport.getCurrentUserId();
        List<UserFollowing> userFollowings = userFollowingService.getUserFans(currentUserId);
        return new JsonResponse<>(userFollowings);
    }

    @PostMapping("/user-following-groups")
    public JsonResponse<Long> addUserFollowingGroup(@ModelAttribute FollowingGroup followingGroup){
        Long currentUserId = UserSupport.getCurrentUserId();
        followingGroup.setUserId(currentUserId);
        Long groupId = followingGroupService.addUserFollowingGroup(followingGroup);
        return new JsonResponse<>(groupId);
    }

    @GetMapping("/user-following-groups")
    public JsonResponse<List<FollowingGroup>> getUserFollowingGroups(){
        Long currentUserId = UserSupport.getCurrentUserId();
        //List<FollowingGroup> userFollowingGroups = followingGroupService.getUserFollowingGroups(currentUserId);
        List<FollowingGroup> userFollowingGroups = followingGroupService.getByUserId(currentUserId);
        return new JsonResponse<>(userFollowingGroups);
    }
}
